package com.cin.cma.server.pos.controller;


import com.cin.cma.common.model.ApiResponse;
import com.cin.cma.common.model.finixx.base.BaseRequest;
import com.cin.cma.common.model.finixx.base.BaseResponse;
import com.cin.cma.common.model.finixx.request.*;
import com.cin.cma.common.model.finixx.response.*;
import com.cin.cma.server.pos.service.ICardService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 会员卡能力
 */
@RestController
@RequestMapping("card")
public class CardController {
    @Autowired
    private ICardService cardService;

    /**
     * 会员卡消费
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("consume")

    public ApiResponse<CardConsumeResponse> consume(@RequestBody @Valid CONCardConsumeRequest model) throws Exception {
        return ApiResponse.success(this.cardService.consume(model));
    }

    /**
     * 获取会员卡信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getCardInfo")

    public ApiResponse<CardInfoResponse> getCardInfo(@RequestBody @Valid CardInfoRequest model) throws Exception {
        return ApiResponse.success(this.cardService.getCardInfo(model));
    }

    /**
     * 会员卡购票消费回滚
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("consumeRollback")

    public ApiResponse<BaseResponse> consumeRollback(@RequestBody @Valid ConsumeRollbackRequest model) throws Exception {
        return ApiResponse.success(this.cardService.consumeRollback(model));
    }

    /**
     * 获取会员卡摘要信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("summaryInfo")

    public ApiResponse<SummaryInfoResponse> summaryInfo(@RequestBody @Valid CardSummaryInfoRequest model) throws Exception {
        return ApiResponse.success(this.cardService.summaryInfo(model));
    }

    /**
     * 卡充值
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("addMoney")

    public ApiResponse<CardAddMoneyResponse> addMoney(@RequestBody @Valid CardAddMoneyRequest model) throws Exception {
        return ApiResponse.success(this.cardService.addMoney(model));
    }

    /**
     * 查询卡消费记录
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("buying")

    public ApiResponse<CardQueryBuyingResponse> buying(@RequestBody @Valid CardBuyingRequest model) throws Exception {
        return ApiResponse.success(this.cardService.buying(model));
    }

    /**
     * 查询卡充值记录
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getAddMoney")

    public ApiResponse<CardQueryAddMoneyResponse> getAddMoney(@RequestBody @Valid CardMarkingRequest model) throws Exception {
        return ApiResponse.success(this.cardService.getAddMoney(model));
    }

    /**
     * 查询卡积分记录
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getMarking")

    public ApiResponse<CardQueryMarkingResponse> getMarking(@RequestBody @Valid CardMarkingRequest model) throws Exception {
        return ApiResponse.success(this.cardService.getMarking(model));
    }

    /**
     * 修改会员卡密码
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("resetPwd")

    public ApiResponse<BaseResponse> resetPwd(@RequestBody @Valid CardUpdatePwdRequest model) throws Exception {
        return ApiResponse.success(this.cardService.resetPwd(model));
    }

    /**
     * 会员卡锁卡
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("lock")

    public ApiResponse<BaseResponse> lock(@RequestBody @Valid CardLockRequest model) throws Exception {
        return ApiResponse.success(this.cardService.lock(model));
    }

    /**
     * 会员卡激活
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("activation")

    public ApiResponse<BaseResponse> activation(@RequestBody @Valid CardActivationRequest model) throws Exception {
        return ApiResponse.success(this.cardService.activation(model));
    }

    /**
     * 修改会员卡信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("editMemberInfo")

    public ApiResponse<BaseResponse> editMemberInfo(@RequestBody @Valid CardEditMemberInfoRequest model) throws Exception {
        return ApiResponse.success(this.cardService.editMemberInfo(model));
    }

    /**
     * 会员卡发卡（卡务必已制卡状态）
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("sell")

    public ApiResponse<CardSellResponse> sell(@RequestBody @Valid CardSellRequest model) throws Exception {
        return ApiResponse.success(this.cardService.sell(model));
    }

    /**
     * 获取卡信息（发卡前）
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getSellInfo")

    public ApiResponse<CardSellInfoResponse> getSellInfo(@RequestBody @Valid CardSellInfoRequest model) throws Exception {
        return ApiResponse.success(this.cardService.sellInfo(model));
    }

    /**
     * 会员卡发卡（卡务必已制卡状态
     *
     * @param model
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("cardSellRecharge")

    public ApiResponse<CardSellRechargeResponse> cardSellRecharge(@RequestBody @Valid CardSellRechargeRequest model) throws Exception {
        return ApiResponse.success(this.cardService.sellRecharge(model));
    }

    /**
     * 获取会员卡使用政策列表
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getUsePolicyList")

    public ApiResponse<CardPrefabricateUsePolicyResponse> getUsePolicyList(@RequestBody @Valid BaseRequest model) throws Exception {
        return ApiResponse.success(this.cardService.getUsePolicyList(model));
    }

    /**
     * 获取会员卡使用政策信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("usePolicy")

    public ApiResponse<CardUsePolicyResponse> usePolicy(@RequestBody @Valid CardUsePolicyRequest model) throws Exception {
        return ApiResponse.success(this.cardService.usePolicy(model));
    }

    /**
     * 获取会员卡等级政策信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getGradeList")

    public ApiResponse<CardPrefabricateGradeResponse> getGradeList(@RequestBody @Valid BaseRequest model) throws Exception {
        return ApiResponse.success(this.cardService.getGradeList(model));
    }
}
